package com.Maykk.Demo02;

import java.util.ArrayList;

/**
 * @ClassName: DemoTest
 * @Description: TODO ArrayList 读写学生类对象
 * @Author: MaykkStar@163.com
 */
public class DemoTest {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        initStu(list);
        show(list);
    }

    /**
     * 输出存储的学生类对象
     * @param list 要输出的学生类对象
     */
    private static void show(ArrayList<Student> list) {
        for (Student stu : list) {
            System.out.printf("%-10s%-8s%-8d\n",
                    stu.getName(),
                    stu.getSex(),
                    stu.getAge()
            );
        }
        // for (int i = 0; i < list.size(); i++) {
        //     System.out.printf("%-10s%-8s%-8d\n",
        //             list.get(i).getName(),
        //             list.get(i).getSex(),
        //             list.get(i).getAge()
        //     );
        // }
    }

    /**
     * ArrayList 存储 Student 类
     * @param list 要存储的学生类对象
     */
    private static void initStu(ArrayList<Student> list) {
        list.add(new Student("程林", "男", 19));
        list.add(new Student("乔平", "女", 17));
        list.add(new Student("刘鹏", "男", 16));
        list.add(new Student("林娇", "女", 14));
    }
}
